package com.xianyu.game.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xianyu.game.Pojo.Game;
import com.xianyu.game.Pojo.IdIntegrates;
import com.xianyu.game.Pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select password from user where username=#{username}")
    String selectPasswordByUsername(User user);

    @Insert("insert into user (username,password,ageisteation_date) values (#{username},#{password},#{ageisteationDate})")
    void registered(User user);

    @Select("select * from user where user_id=#{userID}")
    User getUser(String userId);

    @Insert("insert into inventory (user_id,game_id) values (#{userId},#{gameId})")
    void buyGame(IdIntegrates idIntegrates);

    @Select("select game_id from inventory where user_id=#{userId} and game_id=#{gameId}")
    Integer isBuy(IdIntegrates idIntegrates);

    @Select("select game_id from game_collection where user_id=#{userId} and game_id=#{gameId}")
    Integer isCollection(IdIntegrates idIntegrates);

    @Insert("insert into game_collection (user_id,game_id) values (#{userId},#{gameId})")
    void collectionGame(IdIntegrates idIntegrates);

    @Select("SELECT g.* FROM game g JOIN inventory ug ON g.game_id = ug.game_id WHERE ug.user_id = #{userId}")
    List<Game> getGame(Integer userId);

    @Select("SELECT g.* FROM game g JOIN game_collection gc ON g.game_id = gc.game_id WHERE gc.user_id = #{userId}")
    List<Game> getCollection(Integer userId);

    @Select("select game_id from cart where user_id=#{userId} and game_id=#{gameId} ")
    Integer isExisCart(IdIntegrates idIntegrates);

    @Insert("insert into cart (user_id,game_id) values (#{userId},#{gameId});")
    void addCart(IdIntegrates idIntegrates);
}
